package dao;

import org.junit.Test;
import pojo.City;
import pojo.User;
import utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author konley
 * @date 2020-06-17 22:15
 */
public class CityDao {
    public List<City> FindCity(int pid) {
        List<City> citys = new ArrayList<City>();
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection con = DBUtils.getConnection();
        try {
            ps = con.prepareStatement("select * from city where pid=?");
            ps.setInt(1, pid);
            rs = ps.executeQuery();
            while (rs.next()) {
                City city = new City(
                        rs.getInt("id"),
                        rs.getString("cname"),
                        rs.getInt("pid")
                );
                citys.add(city);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtils.release(rs, ps, con);
        }
        return citys;
    }
}


